package com.framework2.customviews;

import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.yaxin.yyt.R;

/**
 * searchView
 *
 * @author YobertJomi
 * className SearchView
 * created at  2017/3/15  14:29
 */
public class SearchView extends FrameLayout {
    private View viewRoot;
    private ImageView imageView;
    private EditText et_content;

    public SearchView(Context context) {
        super(context);
        init();
    }

    public SearchView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public SearchView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        viewRoot = LayoutInflater.from(getContext()).inflate(
                R.layout.include_search_common, null);
        imageView = (ImageView) viewRoot.findViewById(R.id.imageView);
        et_content = (EditText) viewRoot.findViewById(R.id.searchView_et_content);
        addView(viewRoot);
    }

    /**
     * @param hint hint
     */
    public SearchView setHint(@NonNull CharSequence hint) {
        et_content.setHint(hint);
        return this;
    }

    /**
     * @param resId resId
     */
    public SearchView setHint(@StringRes int resId) {
        et_content.setHint(resId);
        return this;
    }

    /**
     * @param resId resId
     */
    public SearchView setImageResource(@DrawableRes int resId) {
        imageView.setImageResource(resId);
        return this;
    }
}
